#include <iostream>
using namespace std;

//虚基类：无论在继承体系出现多少次，都只保存一份基类的实例
class A{
public:
	A() { cout << "A" << endl; }
	~A() { cout << "~A" << endl; } 

	void func() const { cout << "A::func" << endl; }
};

class B : virtual public A{
public:
	B() { cout << "B" << endl; }
	~B() { cout << "~B" << endl; }

	void func() const { cout << "B::func" << endl; }
};

class C : public virtual A{
public:
	C() { cout << "C" << endl; }
	~C()  { cout << "~C" << endl; }
	void func() const { cout << "C::func" << endl; }
};

class D : public B, public C{
public:
	D(){ cout << "D" << endl; }
	~D() { cout << "~D" << endl; }
};
int main(void)
{
	D d;
	return 0;
}
